package com.qiaofang.collectmanage.task;

import com.github.ltsopensource.core.domain.Action;
import com.github.ltsopensource.core.domain.Job;
import com.github.ltsopensource.core.logger.Logger;
import com.github.ltsopensource.core.logger.LoggerFactory;
import com.github.ltsopensource.tasktracker.Result;
import com.github.ltsopensource.tasktracker.runner.JobContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import java.util.*;

/**
 *  * The type BaseRunner.  * @Description:  * @author xubo  * @Date 2018/1/30  
 */

public abstract class BaseRunner {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    public Result run(JobContext jobContext) throws Throwable {
        String className = this.getClass().getSimpleName();
        logger.info("开始执行任务类:{}", className);
        try {
            Job job = jobContext.getJob();
            // baseRun(null);
        } catch (Exception e) {
            logger.info("执行任务类 :{} 异常:{}", className, e);
            return new Result(Action.EXECUTE_FAILED, e.getMessage());
        }
        logger.info("执行任务类 :{} Success ", className);
        return new Result(Action.EXECUTE_SUCCESS, this.getClass() + " success");
    }

    /**
     * 运行定时任务执行的操作
     *
     */
    public abstract void runJob() throws Exception;

}